<template>
    <span v-loading.fullscreen.lock="loading">...</span>
</template>

<script>
import userApi from "@/api/user.js";

export default {
    data() {
        return {
            loading: false
        }
    },
    created() {
        this.login()
    },
    methods: {
        login: function() {
            var params = this.$route.query
            this.loading = true
            userApi.autoLogin({user_id: parseInt(params.user_id), sign: params.sign, time: parseInt(params.time)}).then(res => {
                this.$store.commit('SET_TOKEN', res.data.data.token)
                this.$store.commit('SET_JWT_URL', res.data.data.redirect)

                // 登录成功后加载跳转到具体的报告页面
                this.loading = false
                if (params.type == 1) {
                    this.$router.push({
                        path: '/auto/my_report',
                        query: {monkey_id: params.monkey_id}
                    })
                } else {
                    this.$router.push({
                        path: '/auto/my_per_report',
                        query: {monkey_id: params.monkey_id}
                    })
                }
            }, error => {
                this.$message.error(error.message)
                this.loading = false
            })
        },
    }
}
</script>
